﻿using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using ModelContextProtocol;

var builder = Host.CreateEmptyApplicationBuilder(settings: null);

//读取环境变量
var configuration = new ConfigurationBuilder()
            .AddEnvironmentVariables().Build();


#region 鉴权走环境变量 逻辑自己改 
string key = configuration["key"];
if (key != "123456")
{
    throw new McpException($"key不正确: '{key}'");
}
#endregion



builder.Services.AddMcpServer()
    .WithStdioServerTransport()
    .WithToolsFromAssembly();



var app = builder.Build();

await app.RunAsync();


//mcp配置如下：
//{
//    "mcpServers": {
//        "tool": {
//            "command": "dotnet",
//           "args": [
//                 "程序所在目录/Mcp_Stdio.dll"
//           ],
//"env": {
//    "key": "123456"
//  }
//        }
//    }
//}